home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_12 / 9n12086a < prev    next >
Text File  |  1991-07-25  |  6KB  |  141 lines

  1. /** LISTING 5 ** UARTMACS.C **************************
  2.         Macro routines used by both
  3.         UARTLOW.C and UARTAPI.C
  4.  
  5. *****************************************************/
  6.  
  7.  
  8. /* The following two variables are required for the
  9.    IO_DELAY macro.  They will automatically be
  10.    defined as global to the including source file.
  11.    They are not system-wide global since the
  12.    interrupt driver and API functions could be 
  13.    utilizing them at the same time. */
  14. static unsigned char g_delay_char;            
  15. static unsigned char g_shift_char;            
  16.  
  17. /*****************************************************
  18. Chew up CPU cycles while I/O port catches up 
  19. *****************************************************/
  20. #define IO_DELAY(delay_loops) {                       \
  21.    for ( g_delay_char = 0 ;                           \
  22.          g_delay_char < delay_loops ;                 \
  23.          g_delay_char++)                              \
  24.        g_shift_char &= g_delay_char;                  \
  25. }
  26.  
  27.  
  28.       
  29. /*****************************************************
  30.   These macros all assume that a local variable 
  31.   p_cur_port_info points to the port info structure
  32.   of the port to be acted on.  They also assume the 
  33.   availability of a local register variable
  34.   value_from_port to use as scratch space.
  35.  
  36.   Also note the terminating \ on each line of the
  37.   macros (except for the closing brace) - it is 
  38.   required because Microsoft C requires that a macro
  39.   be only one line long (the \ is the line
  40.   continuation character).
  41. *****************************************************/
  42.  
  43.  
  44. /*****************************************************
  45. Turn the Data Terminal Ready signal on
  46. *****************************************************/
  47. #define RAISE_DTR {                                   \
  48.    /* Read Modem Control Register */                  \
  49.    value_from_port = inp(p_cur_port_info->            \
  50.         base_address + MODEM_CONTROL_REGISTER);       \
  51.                                                       \
  52.    /* Delay for port to catch up */                   \
  53.    IO_DELAY(2);                                       \
  54.                                                       \
  55.    /* Output the Modem Control Register Value with */ \
  56.    /* the DTR bit activated */                        \
  57.    outp(p_cur_port_info->base_address +               \
  58.         MODEM_CONTROL_REGISTER,                       \
  59.         (value_from_port | 0x01) );                   \
  60.  
  61.  
  62. /*****************************************************
  63. Turn the Data Terminal Ready signal off 
  64. *****************************************************/
  65. #define DROP_DTR {                                    \
  66.    /* Read Modem Control Register */                  \
  67.    value_from_port = inp(p_cur_port_info->            \
  68.         base_address + MODEM_CONTROL_REGISTER);       \
  69.                                                       \
  70.    /* Delay for port to catch up */                   \
  71.    IO_DELAY(2);                                       \
  72.                                                       \
  73.    /* Output the Modem Control Register Value with */ \
  74.    /* the DTR bit deactivated */                      \
  75.    outp(p_cur_port_info->base_address +               \
  76.         MODEM_CONTROL_REGISTER,                       \
  77.         (value_from_port & 0xFE));                    \
  78.  
  79.  
  80. /*****************************************************
  81. Turn the Request To Send signal on
  82. *****************************************************/
  83. #define RAISE_RTS {                                   \
  84.    /* Read Modem Control Register */                  \
  85.    value_from_port = inp(p_cur_port_info->            \
  86.         base_address + MODEM_CONTROL_REGISTER);       \
  87.                                                       \
  88.    /* Delay for port to catch up */                   \
  89.    IO_DELAY(2);                                       \
  90.                                                       \
  91.    /* Output the Modem Control Register Value with */ \
  92.    /* the RTS bit activated */                        \
  93.    outp(p_cur_port_info->base_address +               \
  94.         MODEM_CONTROL_REGISTER,                       \
  95.         (value_from_port | 0x02) );                   \
  96.  
  97.  
  98. /*****************************************************
  99. Turn the Request To Send signal off 
  100. *****************************************************/
  101. #define DROP_RTS {                                    \
  102.    /* Read Modem Control Register */                  \
  103.    value_from_port = inp(p_cur_port_info->            \
  104.         base_address + MODEM_CONTROL_REGISTER);       \
  105.                                                       \
  106.    /* Delay for port to catch up */                   \
  107.    IO_DELAY(2);                                       \
  108.                                                       \
  109.    /* Output the Modem Control Register Value with */ \
  110.    /* the RTS bit deactivated */                      \
  111.    outp(p_cur_port_info->base_address +               \
  112.         MODEM_CONTROL_REGISTER,                       \
  113.         (value_from_port & 0xFD));                    \
  114.  
  115.  
  116. /*****************************************************
  117. Force a Transmit Holding Register Emtpy interrupt to
  118. be generated now if the transmitter is empty.
  119. *****************************************************/
  120. #define BOUNCE_THRE {                                 \
  121.    /* Disable THRE interrupt */                       \
  122.    outp(p_cur_port_info->base_address +               \
  123.         INTERRUPT_ENABLE_REGISTER,0x0D);              \
  124.                                                       \
  125.    /* Delay for port to catch up */                   \
  126.    IO_DELAY(3);                                       \
  127.                                                       \
  128.    /* Re-enable THRE interrupt */                     \
  129.    outp(p_cur_port_info->base_address +               \
  130.         INTERRUPT_ENABLE_REGISTER,0x0F);              \
  131.                                                       \
  132.    /* Delay for port to catch up */                   \
  133.    IO_DELAY(2);                                       \
  134. }
  135.  
  136.  
  137.